package day01_07.day04;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main02{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while(scn.hasNext()){
            int M = scn.nextInt();
            int N = scn.nextInt();
            if (M == 0){
                System.out.print(0);
            }
            else if (N > 9){
                conversionBigTen(M , N);
            }else {
                conversion(M , N);
            }

        }
    }
    public static void conversion(int m , int n){
        ArrayList list = new ArrayList();
        while (m / n != 0){
            list.add(m % n);
            m = m / n;
        }
        if (m % n != 0){
            list.add(m % 2);
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            System.out.print(list.get(i));
        }

    }
    public static void conversionBigTen(int m , int n){
        Map<Integer , String> map = new HashMap<>();
        for (int i = 1; i <= 9; i++) {
            map.put(i , i + "");
        }
        map.put(10 , "A");
        map.put(11 , "B");
        map.put(12 , "C");
        map.put(13 , "D");
        map.put(14 , "E");
        map.put(15 , "F");

        ArrayList list = new ArrayList();
        while (m / n != 0){
            list.add(map.get(m % n));
            m = m / n;
        }
        if (m % n != 0){
            list.add(map.get(m % n));
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            System.out.print(list.get(i));
        }
    }
}

